home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 March / Macworld CD-ROM (March 1995).cdr / Updaters / AppMaker 1.5.2->1.5.4 / Libraries / THINK / AMClassLibC / AMUtilities.cp next >
Encoding:
Text File  |  1991-11-26  |  3.1 KB  |  120 lines  |  [TEXT/KAHL]

  1. /*    AMUtilities.c - common AppMaker library routines    */
  2. /*    Copyright © 1991, Bowers Development Corporation.    */
  3.  
  4. #include <CEditText.h>
  5. #include <CButton.h>
  6. #include <CTextEnvirons.h>
  7. #include <TBUtilities.h>
  8. #include <CError.h>
  9. #include "AMUtilities.h"
  10.  
  11. /*----------*/
  12. void    AMSetFontSizeStyle    (CEditText        *textObject,
  13.                              EditStylesP        p)
  14. {
  15.     textObject->SetFontSize (p->editStyles.textSize);
  16.     textObject->SetFontStyle (NOTHING);    // clear it out then set it
  17.     textObject->SetFontStyle (p->editStyles.textStyle);
  18.     textObject->SetAlignment (p->textJust);
  19.     textObject->SetFontNumber (AMGetFontNum (p->editStyles.fontName));
  20.  
  21. } /* AMSetFontSizeStyle */
  22.  
  23. /*----------*/
  24. void    AMSetTextID            (CEditText        *textObject,
  25.                              short            textID)
  26. {
  27.     Handle            theText;
  28.  
  29.     if (textID > 0) {        /* there is a TEXT resource */
  30.         theText = GetResource ('TEXT', textID);
  31.         CheckResource (theText);
  32.         textObject->SetTextHandle (theText);
  33.         ReleaseResource (theText);
  34.     }
  35.  
  36. } /* AMSetTextID */
  37.  
  38. /*----------*/
  39. short    AMGetFontNum        (Str255            fontName)
  40. {
  41.     short            fontNum;
  42.     
  43.     if (fontName [0] == 0) {
  44.         fontNum = systemFont;
  45.     } else if (EqualString (fontName, "\pA", FALSE, TRUE)) {
  46.         fontNum = applFont;
  47.     } else {
  48.         GetFNum (fontName, &fontNum);
  49.     }
  50.     return (fontNum);
  51.  
  52. } /* AMGetFontNum */
  53.  
  54. /*----------*/
  55. void    AMSetupTextEnvirons    (CPane            *thePane,
  56.                              StylesP        p)
  57. {
  58.     CTextEnvirons        *textEnvirons;
  59.     TextInfoRec            textInfo;
  60.  
  61.     /* create the text environment, using information from the control pane */ 
  62.     textEnvirons = new CTextEnvirons;
  63.     thePane->itsEnvironment = textEnvirons;
  64.     textEnvirons->ITextEnvirons ();
  65.  
  66.     textInfo.fontNumber = AMGetFontNum (p->fontName);
  67.     textInfo.theSize = p->textSize;
  68.     textInfo.theStyle = p->textStyle;
  69.     textInfo.theMode = srcOr;
  70.     textEnvirons->SetTextInfo (&textInfo);
  71.  
  72. } /* AMSetupTextEnvirons */
  73.  
  74. /*----------*/
  75. void    IAMControlPane        (CButton        *controlObject,
  76.                              CView            *anEnclosure,
  77.                              CBureaucrat    *aSupervisor,
  78.                              Ptr            viewData)
  79. {
  80.     register AMCtlPaneTempP        p;
  81.     short            strSize;
  82.     StylesP            stylesPtr;
  83.  
  84.     /* initialize the superclass */
  85.     /* all control panes, as subclasses of CButton, call INewButton        */
  86.     /* so that the procID can be specified.                                */
  87.  
  88.     p = (AMCtlPaneTempP) viewData;
  89.     controlObject->INewButton  (p->sPaneTemp.width, p->sPaneTemp.height, 
  90.                             p->sPaneTemp.hEncl, p->sPaneTemp.vEncl,
  91.                             p->title, (p->sPaneTemp.sViewTemp.visible != 0), p->procID, 
  92.                             anEnclosure, aSupervisor);
  93.  
  94.     if (p->sPaneTemp.sViewTemp.wantsClicks == 0) {
  95.         controlObject->Deactivate ();
  96.     }
  97.  
  98.     // Note: some fields of the ctlPane template are ignored.
  99.     // The related instance variables are set to standard values:
  100.     // hSizing = vSizing = sizFIXEDSTICKY
  101.     // autoRefresh = TRUE;
  102.     // printClip = clipFRAME;
  103.     // wantsClicks = TRUE;
  104.     
  105.     strSize = 1 + p->title [0];
  106.     strSize += (strSize & 1);        // bump to even number
  107.     stylesPtr = (StylesP) &p->title [strSize];
  108.     AMSetupTextEnvirons (controlObject, stylesPtr);
  109.  
  110.     /* set the control values using information from the control pane */  
  111.     controlObject->SetMinValue (p->minValue);
  112.     controlObject->SetMaxValue (p->maxValue);
  113.     controlObject->SetValue (p->curValue);
  114.  
  115.     controlObject->SetClickCmd (p->clickCmd);
  116.  
  117. } /* IAMControlPane */
  118.  
  119. /* AMUtilities */
  120.